# Provided by Chuck Fouts (my officemate and local Ruby User Group leader)

require 'fileutils'

#watch_file = ARGV.shift
#dest_file = ARGV.shift
watch_file = "user-extensions.js"
dest_file = "#{ENV['SELENIUM_HOME']}/core/scripts/user-extensions.js"

puts "Watching [#{watch_file}]"

#abort "Missing filename. \nusage: watch_n_move filename dest_filename" unless watch_file && dest_file
#abort "Invalid filename.  #{watch_file} is not a file." unless File.exist?(watch_file)

watch_file_time = File.mtime( watch_file ) 

while (true)
  new_time = File.mtime( watch_file )
  if watch_file_time < File.mtime( watch_file )
    FileUtils.cp( watch_file, dest_file )
    watch_file_time = new_time
    puts "Updated #{dest_file}"
  end

  sleep( 5 )
end
